home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Treccani Italiana Di Scienze Lettere Ed Arti
/
[Enciclopedia] Treccani Italiana di scienze lettere ed arti.iso
/
pc
/
data
/
xxi_appendice_dvd.swf
/
scripts
/
__Packages
/
CTooltipManager.as
< prev
next >
Wrap
Text File
|
2007-11-08
|
9KB
|
281 lines
class CTooltipManager
{
var hookPrefix = "old_";
function CTooltipManager()
{
}
static function getInstance()
{
if(CTooltipManager._INSTANCE == null)
{
CTooltipManager._INSTANCE = new CTooltipManager();
}
return CTooltipManager._INSTANCE;
}
function init(target, depth)
{
this.container_mc = target.createEmptyMovieClip("container_mc" + depth,depth);
this._showShadow = false;
this._hAlign = "right";
this._vAlign = "down";
this._offsetX = 0;
this._offsetY = 20;
this._delay = 1000;
this._duration = 4000;
this._follow = false;
this._autoHide = true;
this._enabled = true;
this._tipStyle = {textFormat:new TextFormat("Arial Unicode MS",11,0,_global.gUseEmbeddedFont),borderThickness:1,borderColor:13291203,borderAlpha:100,fillColor:16703400,fillAlpha:90,shadowColor:0,shadowAlpha:60,shadowSize:1,shadowOffset:4};
}
function checkDelay()
{
if(getTimer() > this.startTime + Number(this.getProp("delay")))
{
this.createToolTip();
}
}
function createToolTip()
{
this.startTime = getTimer();
this.createField();
this.createBackground();
this.createBorder();
if(this._showShadow)
{
this.createShadow();
}
this.setPosition();
this.tip_mc.onEnterFrame = mx.utils.Delegate.create(this,this.checkDuration);
}
function checkDuration()
{
if(Boolean(this.getProp("follow")))
{
this.setPosition();
}
if(getTimer() > this.startTime + Number(this.getProp("duration")))
{
if(Boolean(this.getProp("autoHide")))
{
this.hide();
}
}
}
function createField()
{
this.tip_mc.createTextField("txtField",3,Number(this.getStyle("borderThickness")),Number(this.getStyle("borderThickness")),200,20);
this.txtField = TextField(this.tip_mc.txtField);
this.txtField.autoSize = true;
this.txtField.multiline = true;
this.txtField.selectable = false;
this.txtField.html = true;
this.txtField.setNewTextFormat(TextFormat(this.getStyle("textFormat")));
this.txtField.htmlText = this.tipText;
this.txtField.embedFonts = _global.gUseEmbeddedFont;
}
function createBackground()
{
this.drawRect(this.tip_mc.createEmptyMovieClip("bg_mc",2),this.txtField._x,this.txtField._y,this.txtField._width,this.txtField._height,{color:Number(this.getStyle("fillColor")),alpha:Number(this.getStyle("fillAlpha"))});
}
function createBorder()
{
var _loc4_ = 0;
var _loc3_ = 0;
var _loc6_ = this.txtField._width + Number(this.getStyle("borderThickness")) * 2;
var _loc5_ = this.txtField._height + Number(this.getStyle("borderThickness")) * 2;
var _loc2_ = this.tip_mc.createEmptyMovieClip("border_mc",1);
_loc2_.lineStyle(Number(this.getStyle("borderThickness")),Number(this.getStyle("borderColor")),Number(this.getStyle("borderAlpha")));
_loc2_.moveTo(_loc4_,_loc3_);
_loc2_.lineTo(_loc4_ + _loc6_,_loc3_);
_loc2_.lineTo(_loc4_ + _loc6_,_loc3_ + _loc5_);
_loc2_.lineTo(_loc4_,_loc3_ + _loc5_);
_loc2_.lineTo(_loc4_,_loc3_);
}
function createShadow()
{
this.drawRect(this.tip_mc.createEmptyMovieClip("shadow_mc",0),Number(this.getStyle("shadowOffset")),Number(this.getStyle("shadowOffset")),this.txtField._width + Number(this.getStyle("borderThickness")) * 2 + Number(this.getStyle("shadowSize")) - Number(this.getStyle("shadowOffset")),this.txtField._height + Number(this.getStyle("borderThickness")) * 2 + Number(this.getStyle("shadowSize")) - Number(this.getStyle("shadowOffset")),{color:Number(this.getStyle("shadowColor")),alpha:Number(this.getStyle("shadowAlpha"))});
}
function drawRect(mc, x, y, w, h, style)
{
mc.moveTo(x,y);
mc.beginFill(style.color,style.alpha);
mc.lineTo(x + w,y);
mc.lineTo(x + w,y + h);
mc.lineTo(x,y + h);
mc.lineTo(x,y);
mc.endFill();
}
function setPosition()
{
var _loc3_ = Number(this.getProp("offsetX"));
var _loc2_ = Number(this.getProp("offsetY"));
if(String(this.getProp("hAlign")) == "left")
{
this.tip_mc._x = this.container_mc._xmouse - this.tip_mc._width + _loc3_;
}
else if(String(this.getProp("hAlign")) == "right")
{
this.tip_mc._x = this.container_mc._xmouse + _loc3_;
}
if(String(this.getProp("vAlign")) == "up")
{
this.tip_mc._y = this.container_mc._ymouse - this.tip_mc._height + _loc2_;
}
else if(String(this.getProp("vAlign")) == "down")
{
this.tip_mc._y = this.container_mc._ymouse + _loc2_;
}
if(this.container_mc._xmouse - this.tip_mc._width + _loc3_ < 0)
{
this.tip_mc._x = this.container_mc._xmouse + Math.max(10,_loc3_);
}
if(this.container_mc._xmouse + this.tip_mc._width + _loc3_ > Stage.width)
{
this.tip_mc._x = this.container_mc._xmouse - this.tip_mc._width - _loc3_;
}
if(this.container_mc._ymouse - this.tip_mc._height + _loc2_ < 0)
{
this.tip_mc._y = this.container_mc._ymouse + Math.max(20,_loc2_);
}
if(this.container_mc._ymouse + this.tip_mc._height + _loc2_ > Stage.height)
{
this.tip_mc._y = this.container_mc._ymouse - this.tip_mc._height - _loc2_;
}
}
function hookEvent(mc, event, handler, scope)
{
var prefix = this.hookPrefix;
mc[prefix + event] = mc[event];
var args = arguments.slice(4);
mc[event] = function()
{
handler.apply(scope,args);
mc[prefix + event]();
};
}
function restoreEvent(mc, event)
{
mc[event] = mc[this.hookPrefix + event];
}
function getProp(prop)
{
return this.overrides[prop] == undefined ? this[prop] : this.overrides[prop];
}
function getStyle(prop)
{
return this.overrides.tipStyle[prop] == undefined ? this.__get__tipStyle()[prop] : this.overrides.tipStyle[prop];
}
function addTip(mc, tipText, overrides)
{
this.hookEvent(mc,"onRollOver",this.show,this,tipText,overrides);
this.hookEvent(mc,"onRollOut",this.hide,this);
this.hookEvent(mc,"onDragOut",this.hide,this);
}
function removeTip(mc)
{
this.restoreEvent(mc,"onRollOver");
this.restoreEvent(mc,"onRollOut");
this.restoreEvent(mc,"onDragOut");
}
function show(tipText, overrides)
{
this.tipText = tipText;
this.overrides = overrides;
if(!Boolean(this.getProp("enabled")))
{
return undefined;
}
this.startTime = getTimer();
this.tip_mc = this.container_mc.createEmptyMovieClip("tip_mc",0);
this.tip_mc.onEnterFrame = mx.utils.Delegate.create(this,this.checkDelay);
}
function hide()
{
this.tip_mc.removeMovieClip();
}
function destroy()
{
this.container_mc.removeMovieClip();
}
function get hAlign()
{
return this._hAlign;
}
function set hAlign(newHAlign)
{
this._hAlign = newHAlign;
}
function get vAlign()
{
return this._vAlign;
}
function set vAlign(newVAlign)
{
this._vAlign = newVAlign;
}
function get offsetX()
{
return this._offsetX;
}
function set offsetX(newOffsetX)
{
this._offsetX = newOffsetX;
}
function get offsetY()
{
return this._offsetY;
}
function set offsetY(newOffsetY)
{
this._offsetY = newOffsetY;
}
function get delay()
{
return this._delay;
}
function set delay(newDelay)
{
this._delay = newDelay;
}
function get duration()
{
return this._duration;
}
function set duration(newDuration)
{
this._duration = newDuration;
}
function get follow()
{
return this._follow;
}
function set follow(mode)
{
this._follow = mode;
}
function get autoHide()
{
return this._autoHide;
}
function set autoHide(mode)
{
this._autoHide = mode;
}
function get tipStyle()
{
return this._tipStyle;
}
function set tipStyle(newTipStyle)
{
this._tipStyle = newTipStyle;
}
function get enabled()
{
return this._enabled;
}
function set enabled(mode)
{
this._enabled = mode;
}
}